﻿namespace CompanyPayRollSystem.BusinessLayer
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using CompanyPayRollSystem.Database;

    /// <summary>
    /// Manager for Department table
    /// </summary>
    public class DepartmentManager : EntityManager
    {
        /// <summary>
        /// Gets the departments.
        /// </summary>
        /// <returns>List of all departments</returns>
        public static List<Department> GetDepartments()
        {
            List<Department> departments = Context.Departments.ToList<Department>();
            return departments;
        }

        /// <summary>
        /// Adds the department.
        /// </summary>
        /// <param name="departmentName">Name of the department.</param>
        public static void AddDepartment(string departmentName)
        {
            Department department = new Department();
            department.DepartmentName = departmentName;

            try
            {
                Context.Departments.InsertOnSubmit(department);
                Context.SubmitChanges();
            }
            catch (Exception ex)
            {
                // Log Exception
                Utilities.Logger.LogException(ex);
                throw ex;
            }
        }
    }
}
